
package com.projects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import cn.stylefeng.roses.core.config.WebAutoConfiguration;

/**
 * SpringBoot方式启动类

 */
@SpringBootApplication(exclude = {WebAutoConfiguration.class})
@EnableScheduling
public class StartApplication {

    private final static Logger logger = LoggerFactory.getLogger(StartApplication.class);

    
    
    private CorsConfiguration buildConfig() {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.addAllowedHeader("*");
        corsConfiguration.addAllowedMethod("*");
        corsConfiguration.setAllowCredentials(true);
        corsConfiguration.setMaxAge(3600l);
        return corsConfiguration;
    }

    
    /**
     * 跨域过滤器
     * @return
     */
    @Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", buildConfig()); 
        return new CorsFilter(source);
    }

    
    
    public static void main(String[] args) {
        SpringApplication.run(StartApplication.class, args);
        logger.info(StartApplication.class.getSimpleName() + " is success!");
    }
}
